<?php

namespace App\Http\Middleware\Auth;

use App\Http\Services\Manage\AdminService;
use App\Http\Services\Manage\LoginService;
use App\Repositories\Manage\TeamAdminRepository;
use Closure;
use App\Models\AdminUser;
use App\Models\TeamAdmin;
use Illuminate\Support\Facades\Cookie;

/**
 * Class ManageLogin
 * @package App\Http\Middleware\Auth
 */
class ManageLogin
{
    /**
     * Manage角色鉴权
     */
    public function handle($request, Closure $next)
    {
        $userInfo = login_user();
        if (empty($userInfo)) {
            $ref = $request->getRequestUri();
            //跳转到登录页
            return redirect('/login?ref=' . $ref);
        }

        $menuId = [];
        if ($_COOKIE['level_1'] > 0) {
            $menuId[] = $_COOKIE['level_1'];
        }
        if ($_COOKIE['level_2'] > 0) {
            $menuId[] = $_COOKIE['level_2'];
        }
        if ($_COOKIE['level_3'] > 0) {
            $menuId[] = $_COOKIE['level_3'];
        }
        view()->share('menu_id', $menuId);
        view()->share('userinfo', $userInfo);
        return $next($request);

        return $next($request);
    }
}
